
*------------------------------------------------------------------------------*
* Authors: 		Sabine C. Carey (University of Mannheim) and 
*				Juergen Brandsch (KfW Development Bank)
* Article: 		Borders and bullies: How borders shape perceptions of security and foreign policy preferences
* Journal: 		Research & Politics 
* Date: 		2024-01
* Instructions: This do file replicates all tables and figures in the appendix
* Stata:		All estimations were done with Stata 18. 			
*------------------------------------------------------------------------------*

clear
set more off


*--------------------------------------------------
* Install packages
*--------------------------------------------------
*	for saving results in memory
	ssc install parmest
	
*	for combinign margins plots
	ssc install combomarginsplot

	
*-------------------
* Load data
*-------------------
	use "cb_Georgia_data_prep.dta"
	global control2 heard_violence harmed econ_cond uni_degree female i.agecat

	
*--------------------------------------------------
* Table summary statistics (Table A.1.2.)
*--------------------------------------------------

	label var close_01 "Using 0.1° cut-off"
	label var close_03 "Using 0.3° cut-off"	
	label var agecat "Age"
	label var DV_partner "Preferred partner"
	label var europ_values "European politial values"
	label var border_force "Use of force"
	label var d7 "Preferred partner"
	
	# delimit ;
	mlogit d7 borderinsec i.close_03 europ_values
				$control2 , cluster(psu) l(95) nolog
	;
	#delimit cr
	
	# delimit ;
	dtable i.close_01 i.close_03 borderinsec i.border_force i.d7 i.europ_values $control2 if e(sample),
		column(by(hide)) 
		nformat(%7.2f mean sd)
	;
	# delimit cr

	
*--------------------------------------------------
* Figure border detainees (Figure A.1.1.)
*--------------------------------------------------	
	clear all
	use "detainees.dta"
	
	#delimit ;
	twoway line Abkhazia Year,
			lcolor(black) lpattern(solid)
		|| line South_Ossetia Year,
			lcolor(black) lpattern(shortdash) 
	,
	xsize(1.5)
	ysize(1)
	xscale(range(2008 2019) noextend noextend titlegap(+2))
	yscale(range(0 400) noextend titlegap(+2))	   
	ylabel(0(100)400, angle(horizontal) glwidth(*.75) glcolor(gs15) glpattern(solid))
	xlabel(2008(2)2019)
	xticks(2008(1)2019, tlength(*.5))
	ytitle("Official number of detainees")
	xtitle("")
	note("Source: Ministry of Reconciliation and Civic Equality, Georgia")
	legend(
		order(1 "Abkhazia border region" 2 "Tskhinvali/South Ossetia border region")
		size(*1) keygap(*0.5) symxsize(*.5) symysize(*.5) region(lcolor(white))
		cols(1)
		position(6)
	)		
	plotregion(lcolor(white)) 
	graphregion(color(white) lcolor(white) lalign(outside))
	;
	#delimit cr
	graph export "detainees_years.pdf", as(pdf) replace		
clear all	


*--------------------------------------------------
* Figure threats to security (Figure A.1.2.)
*--------------------------------------------------	
	use "cb_Georgia_data_prep.dta"
	order b1_4_new borderinsec b1_3_new b1_7_new b1_1_new b1_2_new b1_6_new b1_5_new b1_77_new 
	
	#delimit ;	
	statplot b1_4_new-b1_77_new, 
		s(sum) 
		graphregion(color(white))
		yscale(noextend titlegap(+2))
		yl(, nogrid)
		ytitle("Number of respondenses")
		note("Q: {it:Which of these, if any, do you think currently pose a} severe" "{it:risk to your personal security?}")
		scheme(s2mono)
	;
	#delimit cr
	graph export "security_risk.pdf", as(pdf) replace
	
	
*--------------------------------------------------
* Main models with DV border insecurity as threat (Table A.1.3)
*--------------------------------------------------		
	global control1 heard_violence harmed econ_cond uni_degree female i.agecat	
	
*** full sample
	logit borderinsec i.close_01 tbilisi $control1, cluster(psu)
	logit borderinsec i.close_03 tbilisi $control1, cluster(psu)

*** border regions only
	logit borderinsec close_SO_03 $control1 if close_03>0, cluster(psu)
	
*** SO Border 03 only
	logit borderinsec $control1 if close_03==1, cluster(psu)

*** AB Border 03 only
	logit borderinsec $control1 if close_03==2, cluster(psu)		


*--------------------------------------------------
* Main models with DV use of force (Table A.1.4.)
*--------------------------------------------------			
	global control2 borderinsec heard_violence harmed econ_cond uni_degree female i.agecat
	
*** full sample
	mlogit border_force i.close_01 $control2 tbilisi, cluster(psu) l(95) base(2) nolog
	mlogit border_force i.close_03 $control2 tbilisi, cluster(psu) l(95) base(2) nolog
		
*** border regions only
	mlogit border_force close_SO_03 $control2 if close_03>0, cluster(psu) l(95) base(2) nolog

*** SO Border 03 only	
	mlogit border_force $control2 if close_03==1, cluster(psu) l(95) base(2) nolog

*** AB Border 03 only	
	mlogit border_force $control2 if close_03==2, cluster(psu) l(95) base(2) nolog

			
*--------------------------------------------------
* Main models with DV preferred partner (Table A.1.5.)
*--------------------------------------------------				
*** full sample
	mlogit DV_partner i.close_01 $control2 tbilisi i.europ_values, cluster(psu) l(95) base(2) nolog
	mlogit DV_partner i.close_03 $control2 tbilisi i.europ_values, cluster(psu) l(95) base(2) nolog

*** border regions only	
	mlogit DV_partner close_SO_03 $control2 i.europ_values if close_03>0, cluster(psu) l(95) base(2) nolog

*** SO Border 03 only		
	mlogit DV_partner $control2 i.europ_values if close_03==1, cluster(psu) l(95) base(2) nolog
	
*** AB Border 03 only
	mlogit DV_partner $control2 i.europ_values if close_03==2, cluster(psu) l(95) base(2) nolog
	
	
*--------------------------------------------------
* DV border insecurity as threat without controls (Table A.1.6.)
*--------------------------------------------------			
	logit borderinsec i.close_01, cluster(psu)		
	logit borderinsec i.close_03, cluster(psu)
	logit borderinsec close_SO_03 if close_03>0, cluster(psu)	

*--------------------------------------------------
* DV use of force without controls (Table A.1.7.)
*--------------------------------------------------			
	mlogit border_force i.close_01, cluster(psu) l(95) base(2) nolog
	mlogit border_force i.close_03, cluster(psu) l(95) base(2) nolog
	mlogit border_force close_SO_03 if close_03>0, cluster(psu) l(95) base(2) nolog
	
*--------------------------------------------------
* DV preferred partner without controls (Table A.1.8.)
*--------------------------------------------------		
	mlogit DV_partner i.close_01, cluster(psu) l(95) base(2) nolog
	mlogit DV_partner i.close_03, cluster(psu) l(95) base(2) nolog	
	mlogit DV_partner close_SO_03 if close_03>0, cluster(psu) l(95) base(2) nolog

	
*--------------------------------------------------
* Predicted probabilities based on Table 1 Model 2 (Figure A.1.3.)
*--------------------------------------------------		
* Control variables
	global control1 tbilisi heard_violence harmed econ_cond uni_degree female i.agecat
	quietly logit borderinsec i.close_03 $control1, cluster(psu)
	
	#delimit ;
	margins close_03, at(
		tbilisi=0 
		harmed=1 
		heard_violence=1 
		agecat=3 
		econ_cond=3 
		female=0 
		uni_degree=0
		) 
	;
	#delimit cr 

	* Plotting the margins 
	#delimit ;
	marginsplot,
			ylabel(.2(.2)0.8, labsize(vsmall) angle(horizontal) grid gstyle(minor))
			ymtick(.2(.1)0.8)
			recast(scatter) xscale(range(0.5 2) extend titlegap(+2))
			leg(off)
			title("")
			xtitle("", size(*.75))
			ytitle("Pr(Border as threat)" , size(small) )
			graphregion(c(white) margin(small))
			plotr(m(large))
			graphregion(margin(large))
			xlabel(0 `" "Outside 0.3°" "border regions" "' 1 `" "Within 0.3°" "SO border region" "' 
			2 `" "Within 0.3°" "AB border region" "', nogrid labsize(small)) 
			ysize(1) xsize(1) 
			scheme(s1mono)
	; 
	#delimit cr
	graph export "margins_border_threat_03.pdf", replace
	
	
*--------------------------------------------------
* Figure preferred partner if no opinion on European values (Figure A.1.4.)
*--------------------------------------------------		
	global control2 borderinsec tbilisi heard_violence harmed econ_cond uni_degree female i.agecat

	# delimit ;
	mlogit DV_partner 
				i.close_03
				$control2
				i.europ_values, cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	estimate store partner_all
	
	* EUROPEAN VALUES DK europ_values_3cat = 1
	* Predicted margins: close_03 = 1 SO border region
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=1
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=2 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=1
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_SO_dk_`x'
	parmest, saving("partner_all_SO_dk_`x'.dta", replace) level(95) idstr("SO_dk_`x'")
	}
		
	* EUROPEAN VALUES DON'T KNOW europ_values_3cat = 2
	* Predicted margins: close_03 = 2 AB 0.3 border region
	
	forvalues x == 1/3 {
	quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=2
			borderinsec=0
			harmed=1 
			heard_violence=1 
			agecat=2 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=1
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_AB_dk_`x'
	parmest, saving("partner_all_AB_dk_`x'.dta", replace) level(95) idstr("AB_dk_`x'")
	}
	
	* EUROPEAN VALUES DON'T KNOW europ_values_3cat = 1
	* Predicted margins: close_03 = 0 outside 0.3 border region
	
	forvalues x = 1/3 {
	quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=0
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=2 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=1
			) 
					predict(outcome(`x'))		
					contrast
					post
		;
		#delimit cr 
	estimates store partner_all_out_ndk_`x'
	parmest, saving("partner_all_out_dk_`x'.dta", replace) level(95) idstr("out_dk_`x'")
	}
	           
 	clear
		use "partner_all_out_dk_1" 
		append using "partner_all_out_dk_2"
		append using "partner_all_out_dk_3"		
		append using "partner_all_SO_dk_1"
		append using "partner_all_SO_dk_2"
		append using "partner_all_SO_dk_3"		
		append using "partner_all_AB_dk_1"
		append using "partner_all_AB_dk_2"
		append using "partner_all_AB_dk_3"

		gen event = substr(idstr,-1,.)
		destring event, replace
		gen id = "SO_border" if regexm(idstr, "SO")
		replace id = "AB_border" if regexm(idstr, "AB")
		replace id = "out_border" if regexm(idstr, "out")
		keep estimate min* max* id event 
		
		encode id, gen(new_id)

			#delimit ; 	
				twoway scatter estimate new_id if event ==1, msize(*.8) mfcolor(gs0) mlcolor(gs0)
						|| rcap min95 max95 new_id if event == 1, lcolor(gs0) lwidth(*1.15)
				|| scatter estimate new_id if event == 2, msymbol(T) msize(*.8) mfcolor(gs5) mlcolor(gs5)  
						|| rcap min95 max95 new_id if event == 2, lcolor(gs5) lwidth(*1.15)
				|| scatter estimate new_id if event == 3, msymbol(D) msize(*.8) mfcolor(gs10) mlcolor(gs10)  
						|| rcap min95 max95 new_id if event == 3, lcolor(gs10) lwidth(*1.15)
				xsize(1) ysize(1) 
				xscale(range(.75 3.25) )
                yscale(range())
				ylabel(0(0.2).8 , valuelabel angle(0) labsize(*.80) grid gstyle(minor))
				ymtick(.1(0.1)0.7)
				xlabel(	1 `" "Within 0.3°" "AB border" "' 
						2 `" "Within 0.3°" "SO border" "' 
						3 `" "Outside 0.3°" "borders" "',
						angle(horizontal) nogrid labsize(*.80))
				xtitle("", size(*.75))
				ytitle("Pr(Preferred military partner)", size(*.80))
				legend(order( 	1 "NATO/EU" 3 "Russia" 5 "Don't know")                                                                         
                                   row(1)
                                   size(*.8)                                          
									keygap(*0.75) 
                                   symxsize(*0.35) 
                                   symysize(*0.5)
								   bm(zero)
                                   region(lcolor(white)) bm(l=12 r=3)
                                   position(6) ring(6) 
                                   )
					title("No value mentioned", size(*.8) color(black))
					plotregion(lcolor(black)) 
                    graphregion(color(white) lcolor(white) lalign(outside))
              ; 
               #delimit cr  
				graph export "margins_partner_dk.pdf", replace			
				
				
*--------------------------------------------------
* Figure preferred partner by age (Figure A.1.5.)
*--------------------------------------------------					
	clear all
	use "cb_Georgia_data_prep.dta"
	global control2 borderinsec tbilisi heard_violence harmed econ_cond uni_degree female i.agecat

	# delimit ;
	mlogit DV_partner 
				i.close_03
				$control2
				i.europ_values, cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	estimate store partner_all
	
	* Youngest cohort
	* SO border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=1
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=1 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_SO_age1_`x'
	parmest, saving("partner_all_SO_age1_`x'.dta", replace) level(95) idstr("SO_age1_`x'")
	}	
	
	* Youngest cohort
	* AB border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=2
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=1 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_AB_age1_`x'
	parmest, saving("partner_all_AB_age1_`x'.dta", replace) level(95) idstr("AB_age1_`x'")
	}		
	
	* Youngest cohort
	* outside border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=0
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=1 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_out_age1_`x'
	parmest, saving("partner_all_out_age1_`x'.dta", replace) level(95) idstr("out_age1_`x'")
	}		
	
 	clear
		use "partner_all_out_age1_1" 
		append using "partner_all_out_age1_2"
		append using "partner_all_out_age1_3"		
		append using "partner_all_SO_age1_1"
		append using "partner_all_SO_age1_2"
		append using "partner_all_SO_age1_3"		
		append using "partner_all_AB_age1_1"
		append using "partner_all_AB_age1_2"
		append using "partner_all_AB_age1_3"

		gen event = substr(idstr,-1,.)
		destring event, replace
		gen id = "SO_border" if regexm(idstr, "SO")
		replace id = "AB_border" if regexm(idstr, "AB")
		replace id = "out_border" if regexm(idstr, "out")
		keep estimate min* max* id event 
		
		encode id, gen(new_id)

			#delimit ; 	
				twoway scatter estimate new_id if event ==1, msize(*.8) mfcolor(gs0) mlcolor(gs0)
						|| rcap min95 max95 new_id if event == 1, lcolor(gs0) lwidth(*1.15)
				|| scatter estimate new_id if event == 2, msymbol(T) msize(*.8) mfcolor(gs5) mlcolor(gs5)  
						|| rcap min95 max95 new_id if event == 2, lcolor(gs5) lwidth(*1.15)
				|| scatter estimate new_id if event == 3, msymbol(D) msize(*.8) mfcolor(gs10) mlcolor(gs10)  
						|| rcap min95 max95 new_id if event == 3, lcolor(gs10) lwidth(*1.15)
				xsize(1) ysize(1) 
				xscale(range(.75 3.25) )
                yscale(range())
				ylabel(0(0.2).8 , valuelabel angle(0) labsize(*.80) grid gstyle(minor))
				ymtick(.1(0.1)0.7)
				xlabel(	1 `" "Within 0.3°" "AB border" "' 
						2 `" "Within 0.3°" "SO border" "' 
						3 `" "Outside 0.3°" "borders" "',
						angle(horizontal) nogrid labsize(*.80))
				xtitle("", size(*.75))
				ytitle("Pr(Preferred military partner)", size(*.80))
				legend(order( 	1 "NATO/EU" 3 "Russia" 5 "Don't know")                                                                         
                                   row(1)
                                   size(*.8)                                          
									keygap(*0.75) 
                                   symxsize(*0.35) 
                                   symysize(*0.5)
								   bm(zero)
                                   region(lcolor(white)) bm(l=12 r=3)
                                   position(6) ring(6) 
                                   )
					title("Age cohort 18-40", size(*.8) color(black))
					plotregion(lcolor(black)) 
                    graphregion(color(white) lcolor(white) lalign(outside))
              ; 
               #delimit cr  
				graph export "margins_partner_age1.pdf", replace			
	
* Middle age cohort	
	clear all
	use "cb_Georgia_data_prep.dta"
	global control2 borderinsec tbilisi heard_violence harmed econ_cond uni_degree female i.agecat

	# delimit ;
	mlogit DV_partner 
				i.close_03
				$control2
				i.europ_values, cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	estimate store partner_all
	
	* Middle age cohort
	* SO border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=1
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=2 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_SO_age2_`x'
	parmest, saving("partner_all_SO_age2_`x'.dta", replace) level(95) idstr("SO_age2_`x'")
	}	
	
	* Middle age cohort
	* AB border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=2
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=2 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_AB_age2_`x'
	parmest, saving("partner_all_AB_age2_`x'.dta", replace) level(95) idstr("AB_age2_`x'")
	}		
	
	* Middle age cohort
	* outside border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=0
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=2 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_out_age2_`x'
	parmest, saving("partner_all_out_age2_`x'.dta", replace) level(95) idstr("out_age2_`x'")
	}		
	
 	clear
		use "partner_all_out_age2_1" 
		append using "partner_all_out_age2_2"
		append using "partner_all_out_age2_3"		
		append using "partner_all_SO_age2_1"
		append using "partner_all_SO_age2_2"
		append using "partner_all_SO_age2_3"		
		append using "partner_all_AB_age2_1"
		append using "partner_all_AB_age2_2"
		append using "partner_all_AB_age2_3"

		gen event = substr(idstr,-1,.)
		destring event, replace
		gen id = "SO_border" if regexm(idstr, "SO")
		replace id = "AB_border" if regexm(idstr, "AB")
		replace id = "out_border" if regexm(idstr, "out")
		keep estimate min* max* id event 
		
		encode id, gen(new_id)

			#delimit ; 	
				twoway scatter estimate new_id if event ==1, msize(*.8) mfcolor(gs0) mlcolor(gs0)
						|| rcap min95 max95 new_id if event == 1, lcolor(gs0) lwidth(*1.15)
				|| scatter estimate new_id if event == 2, msymbol(T) msize(*.8) mfcolor(gs5) mlcolor(gs5)  
						|| rcap min95 max95 new_id if event == 2, lcolor(gs5) lwidth(*1.15)
				|| scatter estimate new_id if event == 3, msymbol(D) msize(*.8) mfcolor(gs10) mlcolor(gs10)  
						|| rcap min95 max95 new_id if event == 3, lcolor(gs10) lwidth(*1.15)
				xsize(1) ysize(1) 
				xscale(range(.75 3.25) )
                yscale(range())
				ylabel(0(0.2).8 , valuelabel angle(0) labsize(*.80) grid gstyle(minor))
				ymtick(.1(0.1)0.7)
				xlabel(	1 `" "Within 0.3°" "AB border" "' 
						2 `" "Within 0.3°" "SO border" "' 
						3 `" "Outside 0.3°" "borders" "',
						angle(horizontal) nogrid labsize(*.80))
				xtitle("", size(*.75))
				ytitle("Pr(Preferred military partner)", size(*.80))
				legend(order( 	1 "NATO/EU" 3 "Russia" 5 "Don't know")                                                                         
                                   row(1)
                                   size(*.8)                                          
									keygap(*0.75) 
                                   symxsize(*0.35) 
                                   symysize(*0.5)
								   bm(zero)
                                   region(lcolor(white)) bm(l=12 r=3)
                                   position(6) ring(6) 
                                   )
					title("Age cohort 41-60", size(*.8) color(black))
					plotregion(lcolor(black)) 
                    graphregion(color(white) lcolor(white) lalign(outside))
              ; 
               #delimit cr  
				graph export "margins_partner_age2.pdf", replace		
				
* Oldest age cohort	
	clear all
	use "cb_Georgia_data_prep.dta"
	global control2 borderinsec tbilisi heard_violence harmed econ_cond uni_degree female i.agecat

	# delimit ;
	mlogit DV_partner 
				i.close_03
				$control2
				i.europ_values, cluster(psu) l(95) base(2) nolog
	;
	#delimit cr
	estimate store partner_all
	
	* oldest age cohort
	* SO border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=1
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=3 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_SO_age3_`x'
	parmest, saving("partner_all_SO_age3_`x'.dta", replace) level(95) idstr("SO_age3_`x'")
	}	
	
	* Oldest age cohort
	* AB border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=2
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=3 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_AB_age3_`x'
	parmest, saving("partner_all_AB_age3_`x'.dta", replace) level(95) idstr("AB_age3_`x'")
	}		
	
	* Oldest age cohort
	* outside border area
	forvalues x = 1/3 {
		quietly	estimate restore partner_all
		#delimit ;
			margins, at(close_03=0
			borderinsec=0
			tbilisi=0
			harmed=1 
			heard_violence=1 
			agecat=3 
			econ_cond=3 
			female=1 
			uni_degree=0
			europ_values=3
			) 
		predict(outcome(`x'))		
		contrast
		post
		;
		#delimit cr 
	estimates store partner_all_out_age3_`x'
	parmest, saving("partner_all_out_age3_`x'.dta", replace) level(95) idstr("out_age3_`x'")
	}		
	
 	clear
		use "partner_all_out_age3_1" 
		append using "partner_all_out_age3_2"
		append using "partner_all_out_age3_3"		
		append using "partner_all_SO_age3_1"
		append using "partner_all_SO_age3_2"
		append using "partner_all_SO_age3_3"		
		append using "partner_all_AB_age3_1"
		append using "partner_all_AB_age3_2"
		append using "partner_all_AB_age3_3"

		gen event = substr(idstr,-1,.)
		destring event, replace
		gen id = "SO_border" if regexm(idstr, "SO")
		replace id = "AB_border" if regexm(idstr, "AB")
		replace id = "out_border" if regexm(idstr, "out")
		keep estimate min* max* id event 
		
		encode id, gen(new_id)

			#delimit ; 	
				twoway scatter estimate new_id if event ==1, msize(*.8) mfcolor(gs0) mlcolor(gs0)
						|| rcap min95 max95 new_id if event == 1, lcolor(gs0) lwidth(*1.15)
				|| scatter estimate new_id if event == 2, msymbol(T) msize(*.8) mfcolor(gs5) mlcolor(gs5)  
						|| rcap min95 max95 new_id if event == 2, lcolor(gs5) lwidth(*1.15)
				|| scatter estimate new_id if event == 3, msymbol(D) msize(*.8) mfcolor(gs10) mlcolor(gs10)  
						|| rcap min95 max95 new_id if event == 3, lcolor(gs10) lwidth(*1.15)
				xsize(1) ysize(1) 
				xscale(range(.75 3.25) )
                yscale(range())
				ylabel(0(0.2).8 , valuelabel angle(0) labsize(*.80) grid gstyle(minor))
				ymtick(.1(0.1)0.7)
				xlabel(	1 `" "Within 0.3°" "AB border" "' 
						2 `" "Within 0.3°" "SO border" "' 
						3 `" "Outside 0.3°" "borders" "',
						angle(horizontal) nogrid labsize(*.80))
				xtitle("", size(*.75))
				ytitle("Pr(Preferred military partner)", size(*.80))
				legend(order( 	1 "NATO/EU" 3 "Russia" 5 "Don't know")                                                                         
                                   row(1)
                                   size(*.8)                                          
									keygap(*0.75) 
                                   symxsize(*0.35) 
                                   symysize(*0.5)
								   bm(zero)
                                   region(lcolor(white)) bm(l=12 r=3)
                                   position(6) ring(6) 
                                   )
					title("Age cohort 61-98", size(*.8) color(black))
					plotregion(lcolor(black)) 
                    graphregion(color(white) lcolor(white) lalign(outside))
              ; 
               #delimit cr  
		graph export "margins_partner_age3.pdf", replace					
	
* END appendix
